import { defineStore } from "pinia";
import { getVulnerabilityType, getVulnSource } from "@/api/vulnerability";

export const useCommonStore = defineStore("common", {
  state: () => ({
    // 漏洞类型列表
    vulnTypeList: [],
    // 漏洞来源列表
    sourceList: [],
    // 漏洞验证任务-任务id
    taskId:"",
    // 漏洞验证任务-qemu_id
    qemu_id:"",
    // 漏洞验证恩物-任务
    vuln_title:"",
    // 漏洞验证恩物-环境类型
    vuln_type:"",
    // 漏洞环境验证-id
    envId:"",
    // 漏洞验证任务-任务名
    task_name:"",

    envName:"",
    envComment:"",
  }),
  actions: {
    async getVulnTypeList() {
      const res = await getVulnerabilityType();
      this.vulnTypeList = res.data || [];
    },
    async getVulnSourceList() {
      const res = await getVulnSource();
      this.sourceList = res.data || [];
    },
    getTaskId(){
      return this.taskId;
    },
    getQemuId(){
      return this.qemu_id;
    },
    getVulnTitle(){
      return this.vuln_title;
    },
    setTaskId(val){      
      this.taskId = val;
    },
    setQemuId(val){
      this.qemu_id = val;
    },
    setVulnTitle(val){
      this.vuln_title = val;
    },
    setVulnType(val){
      this.vuln_type = val;
    },
    setTaskName(val){
      this.task_name = val;
    },
    // 漏洞环境验证
    setEnvId(val){
      this.envId = val;
    },
    setEnvName(val){
      this.envName = val;
    },
    setEnvComment(val){
      this.envComment = val;
    },
    getEnvId(){
      return this.envId
    },
    getEnvName(){
      return this.envName;
    },
    getEnvComment(){
      return this.envComment;
    },
    getVulnType(){
      return this.vuln_type;
    },
    getTaskName(){
      return this.task_name;
    },
  },
});
